package com.zhaoyue.study.netty.http;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;

/**
 * @author zhaoyue
 * @description:
 * @create 2018-11-13 下午8:47
 **/
public class HttpFileServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {

    private final String uri;

    public HttpFileServerHandler(String uri) {
        this.uri = uri;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
        //
        if (!msg.decoderResult().isSuccess()) {
            return;
        }


    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }

    /**
     * 如果错误,则发送错误
     *
     * @param ctx
     * @param status
     */
    private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
        FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status,
                Unpooled.copiedBuffer(("fail status:" + status).toString() + "\r\n", CharsetUtil.UTF_8));
        //response.headers().set()
    }
}
